<template>
  <div class="app-container">
    <div class="formDiv">
      <el-form ref="form"  :inline="true">
        <el-row>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="params.mobile" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="福袋领取情况">
              <el-select v-model="params.status"  placeholder="请选择">
                  <el-option label="全部" value="" />
                <el-option label="未完成" :value="0" />
                <el-option label="完成" :value="1" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="用户类型">
              <el-select v-model="params.role" placeholder="请选择">
                 <el-option label="全部" value="" />
                <el-option label="普通用户" :value="1" />
                <el-option label="特约美学设计师" :value="2" />
                <el-option label="高级美学设计师" :value="3" />
                <el-option label="总监" :value="7" />
                <el-option label="总经理" :value="8" />
                <el-option label=" plus会员" :value="11" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="提交时间" width="236">
              <el-date-picker
                v-model="time1"
                type="daterange"
                value-format="yyyy-MM-dd "
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="领取时间" width="236">
              <el-date-picker
                v-model="time"
                type="daterange"
                value-format="yyyy-MM-dd"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-button style="margin-left:60px" type="primary" @click="searchfun">查询</el-button>
            <!-- <el-button style="margin-left:60px" type="primary" @click="exprofun">导出</el-button> -->
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="table">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="index" label="序号" align="center" :index="table_index" width="50" />
        <!-- <el-table-column align="center" prop label="订单号"></el-table-column> -->
        <el-table-column align="center" prop="user_id" label="用户ID" />
        <el-table-column align="center" prop="user.username" label="用户手机号"></el-table-column>
        <el-table-column align="center" prop="user_role" label="用户类型" />
        <el-table-column align="center" prop="money" label="福袋领取情况">
          <template slot-scope="scope">
            <div>
              <span v-if="scope.row.status ==1">完成</span>
              <span v-if="scope.row.status =='0'">未完成</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="created_at" label="提交时间" />
        <el-table-column align="center" prop="ended_at" label="领取时间" />
        <el-table-column align="center" prop="upUsername" label="操作">
          <template slot-scope="scope">
            <div>
              <el-button type="text" size="small" @click="detail(scope.row)">详情</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block" style="margin: 40px 0;">
      <el-pagination
        :current-page="params.page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="params.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>
<script>
import participants from "@/api/participants";
import filter from "@/assets/filter.js";
import { exportfile } from "@/api/commjs/exprot";
export default {
  name: "Participants",
  data() {
    return {
      time1: "",
      time: "",
      total: 0,
      tableData: [],
      params: {
        mobile: "",
        status: "",
        created_at: "",
        ended_at: "",
        role: "",
        page: 1,
        pagesize: 20
      }
    };
  },
  watch: {
    time1() {
      console.log(this.time);

      this.params.created_at = this.time1
        ? this.time1[0] + " " + "-" + " " + this.time1[1]
        : "";
    },
    time() {
      console.log(this.time);
      this.params.ended_at = this.time
        ? this.time[0] + " " + "-" + " " + this.time[1]
        : "";
    }
  },
  created() {
    this.list();
  },
  methods: {
    exprofun() {
      exportfile("admin/fudai/export", this.params, 1);
    },
    // 详情
    detail(data) {
      console.log(data);
      this.$router.push({ name: "partdetail", query: { id: data.id } });
    },
    searchfun() {
      this.params.page = 1;
      this.list();
    },
    async list() {
      console.log(participants);
      const res = await participants.getList(this.params);
      if (res.data.code == 200) {
        this.tableData = res.data.data.data;
        this.total = res.data.data.total;
      } else {
        this.$message.error(res.data.msg);
      }
    },
    table_index(index) {
      return (this.params.page - 1) * this.params.pagesize + index + 1;
    },

    handleSizeChange(val) {
      this.params.page = 1;
      this.params.pagesize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.params.page = val;
      this.list();
    }
  }
};
</script>
